#include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = 1e6+5;
int dp[N][N],a[N],lst[M],pre[N],mx[N];
int n,t;
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> t;
    while(t--) {
        cin >> n;
        for(int i=1; i<=n; i++) {
            cin >> a[i];
            if(i>1) pre[i]=pre[i-1]+(a[i]==a[i-1])*a[i];
        }
        int ans=0;
        memset(dp,0,sizeof(dp));
        memset(mx,0,sizeof(mx));
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=i; j++) {
                dp[i][j]=pre[i]-pre[i-j+1]+mx[i-j];
                if(i==n) ans=max(ans,dp[i][j]);
                mx[i]=max(mx[i],dp[i][j]+(a[i-j]==a[i+1])*a[i+1]);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
